
CV.Tree.implement({

    initHover: function() {
        this.defaults.hoverClass = '';
        this.wrapper.addEvents({
            'mousemove': this.hover.bind(this),
            'mouseout' : this.hover.bind(this)
        });
        this.defaultHoverState = {
            gadjet: false,
            checkbox: false,
            icon: false,
            name: false,
            node: false
        };
        this.hoverState = Object.clone(this.defaultHoverState);
    },
    hover: function() {
        var cnode = this.mouse.node;
        var ctarget = this.mouse.target;
        Object.each(this.hoverState, function(node, target, state) {
            if(node == cnode && (target == 'node' || target == ctarget)) return;
            if(node) {
                CV.Tree.Hover.out(node, target);
                state[target] = false;
                this.fireEvent('hover', [node, target, 'out']);
            }
            if(cnode && (target == 'node'||target == ctarget)) {
                CV.Tree.Hover.over(cnode, target);
                state[target] = cnode;
                this.fireEvent('hover', [cnode, target, 'over']);
            }
            else {
                state[target] = false;
            }
        }, this);
    },
    updateHover: function() {
        this.hoverState = Object.clone(this.defaultHoverState);
        this.hover();
    }
});

CV.Tree.Hover = {

    over: function(node, target) {
        var wrapper = node.getDOM('wrapper');
        wrapper.addClass((node.hoverClass || 'cv-tree-hover') + '-' + target);
        if(node.state.selected) wrapper.addClass((node.hoverClass || 'cv-tree-hover') + '-selected-' + target);
    },
    out: function(node, target) {
        var wrapper = node.getDOM('wrapper');
        wrapper.removeClass((node.hoverClass || 'cv-tree-hover') + '-' + target).removeClass((node.hoverClass || 'cv-tree-hover') + '-selected-' + target);
    }
};
